package vn.edu.hcmut.cse.ai.search.test;

import java.io.File;
import java.util.Scanner;
import vn.edu.hcmut.cse.ai.search.problems.waterjug.*;

public class WaterJug {

    public static void main(String[] args) {
        String pathIn = "./WaterJug.";
        File folder = new File(pathIn);
        File[] listIn = folder.listFiles();
        long start, end; // start time , end time run agorithms
        Scanner scanner = new Scanner(System.in);
        System.out.println("Chose " +"1. DFS" + "\t" + "2. BRFS" + "\t" + "3. First Heuristic" + "\t" + "4. Second Heuristic");
        int choice = scanner.nextInt();
        for (int i = 0; i < 1; i++) {
            i=9;
            ReadInput read = new ReadInput();
            read.handle(listIn[i].getPath());

            int startJug1 = read.getStartJug1();
            int startJug2 = read.getStartJug2();
            int goalJug1 = read.getGoalJug1();
            int goalJug2 = read.getGoalJug2();
            WaterState waterState = new WaterState(startJug1, startJug2);
            WaterState.sizeJug1 = read.getSizeJug1(); // Size Jug 1
            WaterState.sizeJug2 = read.getSizeJug2(); // Size Jug 2
            WaterState goalState = new WaterState(goalJug1, goalJug2);
            WaterActions actions = new WaterActions();
            WaterGoalTest goalTest = new WaterGoalTest(goalState);
            WaterActionCost actionCost = new WaterActionCost();
            WaterProblem problem = new WaterProblem(waterState, actions, goalTest, actionCost);

            System.out.println("Input" + (i + 1) + ':' + '\n');
            System.out.println("Size: " + read.getSizeJug1() + " " + read.getSizeJug2());
            System.out.println("Start State: " + startJug1 + " " + startJug2);
            System.out.println("Goal State: " + goalJug1 + " " + goalJug2);
            System.out.println("Solution: ");
            //BFS
            threadBFS brfs = new threadBFS(problem);
            //DFS
            threadDFS dfs = new threadDFS(problem);
            // first heuristic function
            firstHeuristicFunction firstHeuristic = new firstHeuristicFunction(new WaterJugFirstHeuristicFunction(), problem);
            // second heuristic funtion
            secondHeuristicFunction secondHeuristic = new secondHeuristicFunction(new WaterJugSecondHeuristicFunction(), problem);
            start = System.currentTimeMillis();
            switch (choice){
                case 1:
                    dfs.run(); break;
                case 2:
                    brfs.run(); break;
                case 3:
                    firstHeuristic.run(); break;
                case 4:
                    secondHeuristic.run(); break;
                default:
                    break;
            }
            end = System.currentTimeMillis();
            System.out.println(end - start + " millis seconds");
            System.out.println("-------------------------------");

        }
    }
}